package no.rmz.chez.game.moveSelection;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * An abstract utility class. Provides a single method that
 * will select something from a collection using some
 * selection strategy.
 * @param <T>
 */
abstract public class Selector<T> {

    static final  private Random RANDOM = new Random();
    

    protected  Selector() {

    }

    /**
     * Get an element from the collection.
     * @param possibilities the set of possible return values.
     * @return One of the possibilities.
     */
    public abstract T selectFrom(Collection<T> possibilities);


    /**
     * Get the collection as a vector.
     * @param col A collection of elements.
     * @return A list consisting of all the elements in the collection "col"
     */
    public  List<T> asList(Collection<T> col) {
        List<T> result;
        if (col instanceof List) {
            result = (List<T>) col;
        } else {
            result = new LinkedList<T>(col);
        }

        return result;
    }

    

    public static  Random getRandom() {
        return RANDOM;
    }

}

